//
//  MineHeaderView.swift
//  FrameProduct
//
//  Created by delegate on 2025/10/22.
//

import UIKit

class MineHeaderView: UIView {
    var signInButtonActionBlock: (() -> Void)?
    var shareButtonActionBlock: (() -> Void)?
    override init(frame: CGRect) {
        super.init(frame: frame)
        notLoginFunc()
    }
    
    @objc private func signInButtonAction() {
        signInButtonActionBlock?()
    }
    @objc private func shareButtonAction() {
        shareButtonActionBlock?()
    }
    
    private func loginFunc() {///222
        for view in subviews {
            view.removeFromSuperview()
        }
        addSubviews(headerBgImageView, signInButton, shareButton)
        headerBgImageView.addSubviews(headerIconBgImageView, headerIconImageView, titleLabel, subTitleLabel)
        headerBgImageView.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.height.equalTo(146)
        }
        headerIconBgImageView.snp.makeConstraints { make in
            make.left.equalTo(18)
            make.top.equalTo(17)
            make.width.equalTo(54)
            make.height.equalTo(54)
        }
        headerIconImageView.snp.makeConstraints { make in
            make.top.equalTo(headerIconBgImageView.snp.top).offset(8)
            make.left.equalTo(headerIconBgImageView.snp.left).offset(-2)
            make.width.equalTo(45)
            make.height.equalTo(37)
        }
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(headerIconBgImageView.snp.top).offset(12)
            make.left.equalTo(headerIconBgImageView.snp.right).offset(10)
            make.right.equalTo(-10)
        }
        subTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(headerIconBgImageView.snp.top).offset(12)
            make.left.equalTo(headerIconBgImageView.snp.right).offset(10)
            make.right.equalTo(-10)
        }
        
        signInButton.snp.makeConstraints { make in
            make.top.equalTo(headerBgImageView.snp.bottom).offset(16)
            make.left.equalTo(42)
            make.width.equalTo(108)
            make.height.equalTo(40)
        }
        shareButton.snp.makeConstraints { make in
            make.right.equalTo(-16)
            make.centerY.equalTo(signInButton.snp.centerY)
            make.width.equalTo(108)
            make.height.equalTo(40)
        }
    }
    private func notLoginFunc() {//166
        for view in subviews {
            view.removeFromSuperview()
        }
        addSubviews(headerBgImageView)
        headerBgImageView.addSubviews(headerIconBgImageView, headerIconImageView, titleLabel, signInButton, shareButton)
        headerBgImageView.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.height.equalTo(146)
        }
        headerIconBgImageView.snp.makeConstraints { make in
            make.left.equalTo(28)
            make.top.equalTo(17)
            make.width.equalTo(54)
            make.height.equalTo(54)
        }
        headerIconImageView.snp.makeConstraints { make in
            make.top.equalTo(headerIconBgImageView.snp.top).offset(8)
            make.left.equalTo(headerIconBgImageView.snp.left).offset(-8)
            make.width.equalTo(45)
            make.height.equalTo(37)
        }
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(headerIconBgImageView.snp.top).offset(12)
            make.left.equalTo(headerIconBgImageView.snp.right).offset(10)
            make.right.equalTo(-10)
        }
        
        signInButton.snp.makeConstraints { make in
            make.bottom.equalTo(-16)
            make.left.equalTo(42)
            make.width.equalTo(108)
            make.height.equalTo(40)
        }
        shareButton.snp.makeConstraints { make in
            make.right.equalTo(-16)
            make.centerY.equalTo(signInButton.snp.centerY)
            make.width.equalTo(108)
            make.height.equalTo(40)
        }
    }
    //=================================================================
    //                            lazy
    //=================================================================
    // MARK: - lazy
    private lazy var headerBgImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "mine_header_bg_img")
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    private lazy var headerIconBgImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "mine_header_icon_bg_img")
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    private lazy var headerIconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "mine_header_icon_img")
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    private lazy var titleLabel: UILabel = {
        let label = UILabel(frame: .zero)
        label.text = "未登录"
        label.textColor = .lxs.hex("#FFFFFF")
        label.font = .lxs.font(size: 16)
        return label
    }()
    private lazy var subTitleLabel: UILabel = {
        let label = UILabel(frame: .zero)
        label.text = "普通套餐到期:暂无   高级套餐到期:暂无设备数:1"
        label.textColor = .lxs.hex("#A6A6A6")
        label.font = .lxs.font(size: 12)
        label.numberOfLines = 0
        return label
    }()
    private lazy var signInButton: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitle("签到", for: .normal)
        button.setTitle("签到", for: .selected)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .normal)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .selected)
        button.titleLabel?.font = .lxs.font(size: 12)
        button.setImage(UIImage(named: "mine_sign_in_btn_img"), for: .normal)
        button.setImage(UIImage(named: "mine_sign_in_btn_img"), for: .selected)
        button.setBackgroundImage(UIImage(named: "mine_header_btn_img"), for: .normal)
        button.setBackgroundImage(UIImage(named: "mine_header_btn_img"), for: .selected)
        button.addTarget(self, action: #selector(signInButtonAction), for: .touchUpInside)
        return button
    }()
    private lazy var shareButton: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitle("分享送时长", for: .normal)
        button.setTitle("分享送时长", for: .selected)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .normal)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .selected)
        button.titleLabel?.font = .lxs.font(size: 12)
        button.setImage(UIImage(named: "mine_share_btn_img"), for: .normal)
        button.setImage(UIImage(named: "mine_share_btn_img"), for: .selected)
        button.setBackgroundImage(UIImage(named: "mine_header_btn_img"), for: .normal)
        button.setBackgroundImage(UIImage(named: "mine_header_btn_img"), for: .selected)
        button.addTarget(self, action: #selector(shareButtonAction), for: .touchUpInside)
        return button
    }()
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
